﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SuperDog;

namespace DogCheck
{
    public class DogCheck
    {
        private const int feature = 18932;
        private const bool trialFlag = false;
        private DateTime deadTime = new DateTime(2024,6,1,8,0,0);
        private DateTime TipTime = new DateTime(2024,4,1,8,0,0);
        private const string _vendorCode =
           "ghQvT9JTvpC80G/6L0dn6uZNKJdLn8th0K7vAlnkh3k7VAGFFqk0ooyeVY37nsWJEf860MLe0n+pH2Sy" +
           "G1k7LEOl142sYCqQRO9mn/dmskgjf57LL865V0BzIUTRoJ1ynVPyIUJv05U7WuxexLjnmxC0iu3zb7/K" +
           "+NXqlKNfgx+C88xaQ5fGKhNO/IlAO6CHTJfkVwfUpiFUZStiapbyN1V0TsWBymoizW5I2rkchUgcV8jH" +
           "/R5NJVAvMZuMg+kFzRHy+D5wX2bP5DKcn7Ao5NpLuhbinrUPuZbUeahFxCSmKDG6e5T/fL5yPstQxCGh" +
           "5HLfTKskiPTmfscYtyXY9qhhFp+DMlTY3N/mWk9aZi/Hg0Rgz0Db7ZWhkxUMcC/guALVEJ4yoWuZXgTq" +
           "xArrXJuVYFk7Lgh90XXqQLRnTtnGWXnrdPHsSi0wbQg9DVcfKpqHfq9zkImg9qjw9MWkcfErMEPnYPsQ" +
           "DshdU6mGGXLHv5QLKP7D9pj5AdYi2FGxg9bypuvyXzmDgYS4/2r1iOoZxkl5UznYN017t8qiHpiv0t6I" +
           "sxapRSTUHJlZ6ejOpVBYuz/PSJL93BuxBjjXQUOWAJTPvI6uqTv4ZnMgh99+wU6izF6FODAVkzqgsDpp" +
           "WlYYI2gASnmIlcXB9oXY8oqNOsgYZwKxhrn6nj1kcdXxyxPVJbzpVH6B+N9GG/bjDCQlOoqHVFPhsKYp" +
           "h9wYgy7T1QyAPRqobSontSIn1Z3XMwsCyvFNKBO7ts88MRePs7g2qcGxH6ANIEWVwiQzGg2ummiHiZzI" +
           "Rt8buMnteZ7nMRa1mbxTw1bYLX5LPJ5k3hpc1brADglswpj3Lguw1yte3mhqO2/7TUrxTVtEszL2HnKa" +
           "LWu40SnU3mTDfT9PrXVCh4UvI/SNzEtoCi8Z6mO/byHHcQbjj0/NiprFOm32ygh4TIYDrFyhgLqF1irx" +
           "DrkXyMw0NivtmWxMGea37A==";

        private string _errstr = "";
        public string ErrString
        {
            get { return _errstr; }
        }

        public Dog Dog { get; set; }
        public DogCheck() {

            Dog = new Dog(new DogFeature(feature));
        }
        /// <summary>
        /// 超级狗检查，0时正常，1即将到期，2没有狗或已到期
        /// </summary>
        /// <returns></returns>
        public int Login()
        {
            DogStatus status = Dog.Login(_vendorCode);
            DateTime Vtime = new DateTime();
            Dog.GetTime(ref Vtime);
            
            _errstr = "";
            if (status == DogStatus.StatusOk)
            {
                //MessageBox.Show(Vtime.ToString()+"\n"+TipTime.ToString());
                if (trialFlag)
                {
                    if (Vtime > deadTime)
                    {
                        _errstr = Vtime.ToString() + "授权已经到期，请联系软件作者。" + deadTime.ToString();
                        return 2;
                    }
                    else if (Vtime > TipTime)
                    {
                        _errstr = Vtime.ToString() + "授权即将到期，请尽快获得授权" + TipTime.ToString();
                        return 1;
                    }
                    return 0;
                }
                //正式版
                return 0;
               
            }
            else
            {
                _errstr = $"授权密钥打开失败：{status.ToString()}";
                return 2;
            }
            
        }
        public void LoginOut()
        {
            Dog.Logout();
        }
        
    }
}
